﻿using GsOrganization.Common.Helper;
using GsOrganization.TcpPacket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GsOrganization.TcpServer
{
    /// <summary>
    /// 服务端全局暴露唯一Tcp资源管理类
    /// </summary>
    public static class TcpResourcesManager
    {
        //可访问仅限于当前程序集，其他程序集如若需要访问请使用TcpResourcesManager.GetSession(string clientId)方法获取会话
        internal static CollectServer TcpServer;

        /// <summary>
        /// 获取指定客户端会话
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public static ClientSession GetSession(string clientId)
        {
            var session = TcpServer.GetClientSession(clientId);
            return session;
        }

        /// <summary>
        /// 设置回调方法，添加指令对应的处理函数
        /// </summary>
        /// <param name="commandId"></param>
        /// <param name="action"></param>
        public static void SetAction(ushort commandId, Func<ClientSession, Header, byte[], int> action)
        {
            TcpServer.SetAction(commandId, action);
            LogHelper.Information($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}添加回调方法,回调指令为${commandId}");
        }
    }
}
